﻿using ReadPointsRingNumberExcel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace MetroDataApi.Controllers.View
{
    public class WiSenController : Controller
    {
        //
        // GET: /WiSen/

        public ActionResult Index(string id = "")
        {
            var remoteUrl = @"http://shentong.wisencn.com:50060/dataConvert/file/download.action?fileName=";
            var date = "";
            if (id == "")
            {
                date = DateTime.Now.AddDays(-1).ToString("yyyy_MM_dd") + ".xls";
            }
            else
            {
                date = DateTime.Parse(id).ToString("yyyy_MM_dd") + ".xls";
            }
         
            remoteUrl = remoteUrl + date;

            using (WebClient Client = new WebClient())
            {
                var localPath = System.Web.HttpContext.Current.Server.MapPath(@"~/Excels");
                localPath += @"\" + date;
                Client.DownloadFile(remoteUrl, localPath);
                wisenFileProcess.FileProcess(localPath, localPath);
                ViewBag.url = Url.Content("~/Excels/" + date);
            }
            return View();
        }

    }
}
